Parameter Handling

In this section specify how TPT and MATLAB communicate when exchanging parameter values. All settings can be changed separately, and read or write can be disabled in case these features are not needed. The default setting for TPT is to exchange parameters via MATLAB workspace (WS); this configuration is adequate for most cases (importing, reading, and writing).

With MATLAB, parameter exchange is only possible prior to test execution and NOT during test execution. Any change made to a parameter during test execution has no effect on the SUT.

Parameter exchange configuration

The following options are available for importing, reading and writing:

IMPORT parameters (MATLAB > TPT)

Analyze MATLAB workspace, Simulink DD or TargetLink DD automatically (default)

Automatically import/read from MATLAB or write parameters to MATLAB workspace.

Use custom MATLAB script/function

A cell array that contains strings is imported as string array parameter. Only string arrays of the form {'a', 'b'} are supported by TPT. Cell array parameters are read during the test execution.

Parameters can be exchanged via a custom MATLAB script or function. This script can especially be used to define parameters as maps, curves, or structs in TPT. Use the following structures to assign the values to the specified parameters:

map:

tpt_read(<i>).name='<nameInTPT>';
tpt_read(<i>).type='map';
tpt_read(<i>).value.xaxis=<value>;
tpt_read(<i>).value.yaxis =<value>;
tpt_read(<i>).value.values=<value>;

curve:

tpt_read(<i>).name='<nameInTPT>';
tpt_read(<i>).type='curve';
tpt_read(<i>).value.axis= <value>;
tpt_read(<i>).value.values =<value>;

struct:

When using the type struct, a field's value may not be a structure itself again.

tpt_read(<i>).name='<nameInTPT>';
tpt_read(<i>).type='struct';
tpt_read(<i>).value.<field1>=<value>;
tpt_read(<i>).value.<...> =<value>;

everything else:

TPT recognizes the data type of arrays, matrix, multidimensional arrays, double, boolean, integer, enumeration, and so forth automatically by its <value>.

tpt_read(<i>).name='<nameInTPT>';
tpt_read(<i>).type='auto';
tpt_read(<i>).value=<value>;

In case you are using Simulink.Parameter objects, Simulink.Signal objects and embedded.fi objects, these objects may not be set directly for a <value>. Extract their values in your script or function and use the extracted value for <value>. For example, params(1).value = mySimPar.Value; for a Simulink.Parameter. Enumerations like Simulink.IntEnumType can however be used as <value>.

Example

In MATLAB we have the following struct parameter:

var1.X = [1 2 3];
var1.Val = [30 20 40];

We want to use this parameter in TPT as a curve. Therefore we write a m-script getMyParams.m for importing and reading the parameter:

myParams(1).name = 'myCurve';
myParams(1).type = 'curve';
myParams(1).value.axis = var1.X;
myParams(1).value.values = var1.Val;

This script is exactly the structure from above for a curve. The name of the curve in TPT is "myCurve". Note that each entry in the parameter structure needs to have an unique index number (1 in this example).

In the parameter handling tab the script will be called using the following line :

getMyParams; ${paramstruct} = myParams; clear myParams;

Import parameter using a custom script

To write this parameter to MATLAB we write a second script setMyParams.m which receives a structure of the same kind from TPT, containing the parameter values from within TPT:

myParams = tptCustomParamMap(myParams);
p = myParams('myCurve');
var1.X = p.value.axis;
var1.Val = p.value.values;

The function tptCustomParamMap transforms the structure into a MATLAB Map Container in order to allow easier access of the parameter entries. It is provided by TPT and may be used within your script.

In the Parameter Handling tab the script we use the following line:

myParams = ${paramstruct}; setMyParams; clear myParams;

Write parameter using a custom script

In the listed examples, the custom scripts explicitly define read/write relations between specific MATLAB parameters and specific TPT parameters. However, when writing custom MATLAB scripts/functions to exchange parameters, you might want to iterate through all parameters in the workspace or in your data dictionary instead - and build up the parameter structure or read from the parameter structure dynamically.

READ parameters before each test execution (MATLAB > TPT)

Disable reading parameters

No parameters are read from MATLAB.

Read parameters as specified for IMPORT parameters (default)

All parameters are read from MATLAB.

Read each parameter using custom expression

Individual parameters are read by means of a ${paramname} expression. For example when you enter ${foo} and ${bar}, MATLAB returns the value only of these two parameters. Use the button at the end of the line to reset your changes.

WRITE parameters before each test execution (TPT > MATLAB)

Disable writing parameters

No parameters are written to MATLAB.

Write parameters to MATLAB workspace, Simulink D or TargetLink DD automatically (default)

All parameters are written to MATLAB.

If the parameter already exists in MATLAB, its data type will be converted to the data type used in MATLAB.

TargetLink: Assign parameter values to memory in SiL/PiL mode

This way the code for the parameters can be reused so there is no need to regenerate the code. This option is not supported for Simulink.Parameter objects. Note the TargetLink limitations for parameter modifications. Refer to the TargetLink manual for detailed information.

Write parameters via custom MATLAB script/function

Write each parameter using custom expression

Parameters are written by a ${paramname}=${paramvalue} command. For example when you write ${foo}=${123}, MATLAB writes the value 123 to the parameter foo. foo can be a scalar parameter, an array, a curve, or a map. Any of these types must be previously entered using the Declaration Editor, see Signal Types - Parameter.

When you use TargetLink 4.2, the MIL handler might crash. If it does, comment it out during the SIL test execution.
Example

Consider a parameter PAR_A in MATLAB (mode: exchange):

PAR_A.value=22

Consider two functions in MATLAB:

Write parameter:

function y = wp (x)

y.value = x

Read parameter:

function y = rdp (x)

y= x.value

Set the exchange preferences as shown below:

Parameter exchange (a)

Parameter exchange (b)